﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Luna小店.service;
using DevExpress.XtraEditors.Popup;
using DevExpress.Utils.Win;
using DevExpress.XtraGrid.Editors;
using DevExpress.XtraLayout;
using Luna小店.Utils;
using DevExpress.XtraGrid.Demos.util;
using mendian;
using Luna小店.DTO;

namespace Luna小店.UC.款式尺寸
{
    public partial class Frm尺寸 : DevExpress.XtraEditors.XtraForm
    {
        private string styleId;
        public Frm尺寸(String styleId)
        {
            InitializeComponent();
            this.styleId = styleId;
            this.gridControl尺寸.DataSource = FunctionHelper.JsonDeserialization<List<DTO尺寸>>(RestCall.httpGetMethod(URL.接口url + "/size/findByStyleId?styleId=" + this.styleId));
        }

        private void simpleButton导入尺寸_Click(object sender, EventArgs e)
        {
            DataSet result = ExcelUtil.getExcelDatas();
            if (result == null)
            {
                return;
            }
            DataTable dataTable = result.Tables[0];
            List<DTO尺寸> list = new List<DTO尺寸>();
            for (int i= 0; i< dataTable.Rows.Count;i++ )
            {
                if (i != 0)
                {
                    String ITEM_CD = dataTable.Rows[i][0].ToString();
                    string ITEM_VALUE = dataTable.Rows[i][1].ToString();
                    string ITEM_NAME_CN = dataTable.Rows[i][2].ToString();
                    for (int j = 3; j < dataTable.Columns.Count; j++)
                    {
                        list.Add(new DTO尺寸(ITEM_CD, ITEM_VALUE, ITEM_NAME_CN, dataTable.Rows[i][j], this.styleId, "IGS_GROUP_SIZE-" + dataTable.Rows[0][j].ToString()));
                    }
                }
            }
            new Frm尺寸导入预览(list).ShowDialog();
        }
    }
    public class DTO尺寸
    {
        public  string itemCd { get; set; }
        public string itemValue { get; set; }
        public string itemNameCn { get; set; }
        public double itemFitValue { get; set; }
        public string fitCd { get; set; }
        public string sizeCd { get; set; }
        public DTO尺寸()
        {
        }
        
        public DTO尺寸(string itemCd, string itemValue, string itemNameCn, object itemFitValue, string fitCd, string sizeCd)
        {
            this.itemCd = itemCd;
            this.itemValue = itemValue;
            this.itemNameCn = itemNameCn;
            try
            {
                this.itemFitValue = Convert.ToDouble(itemFitValue.ToString());
            }
            catch {
                this.itemFitValue = 0.0;
                    }

            this.fitCd = fitCd;
            this.sizeCd = sizeCd;
        }
        
    }
}